﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Classes.DAL
{
    public class Photo
    {
       dbConnection db = new dbConnection();
       public  int CreateImag(CustomersBO Customer)
       {
           SqlConnection cn = null;
           SqlCommand cmd = null;
           int Counter = 0;

           dbConnection db = new dbConnection();

           try
           {
               cn = new SqlConnection();
               cn.ConnectionString = db.GetCS();

               cmd = new SqlCommand();
               cmd.Connection = cn;
               cmd.CommandType = CommandType.Text;
               cmd.CommandText = "INSERT INTO [Customers] ( CustomerName, AccountId,AddressId) values (@CustomerName,@AccountId,@AddressId)";
               cmd.Parameters.AddWithValue("@CustomerName", Customer.CustomerName);
               cmd.Parameters.AddWithValue("@AccountId", Customer.AccountId);
               cmd.Parameters.AddWithValue("@AddressId", Customer.AddressId);


               cn.Open();
               Counter = cmd.ExecuteNonQuery();

           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message);
           }
           finally
           {
               if (cn != null)
               {
                   cn.Close();
                   cn.Dispose();
                   cn = null;
               }
           }
           return (Counter);
       }
       public  int CreateImage(CustomersBO Customer)
       {
           SqlConnection cn = null;
           SqlCommand cmd = null;
           int Counter = 0;

           dbConnection db = new dbConnection();

           try
           {
               cn = new SqlConnection();
               cn.ConnectionString = db.GetCS();

               cmd = new SqlCommand();
               cmd.Connection = cn;
               cmd.CommandType = CommandType.Text;
               cmd.CommandText = "INSERT INTO ImageInfo (ImageName, ImageSize, ImagePath) VALUES  + (@ImgName,@ImgSize,@ImgPath)";


               cmd.Parameters.AddWithValue("@ImageName", Customer.ImageName);
               cmd.Parameters.AddWithValue("@ImageSize", Customer.ImageSize);
               cmd.Parameters.AddWithValue("@ImagePath", Customer.ImagePath);


               cn.Open();
               Counter = cmd.ExecuteNonQuery();

           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message);
           }
           finally
           {
               if (cn != null)
               {
                   cn.Close();
                   cn.Dispose();
                   cn = null;
               }
           }
           return (Counter);



       }

 
    }
}
